< previous page page_120 next page >

Page 120
was accomplished), where only the File and Help menus are visible until a document is selected for editing. After a document is open, the other menu items are shown.
Changing the setting of the Visible property allows you to control what menu items are available to the users at a given point in your program. Controlling the menu this way lets you restrict the users' access to menu items that might cause errors if certain conditions are not met. (You wouldn't want the users to access edit functions if no document was open to edit, right?)
The Enabled property serves a function similar to that of the Visible property. The key difference is that when the Enabled property is set to False, the menu item is grayed out. This means that the menu item still can be seen by the users but cannot be accessed. For example, the standard Edit, Cutand Edit, Copy functions should not be available if no text or object is selected, but nothing is wrong with letting the users see that these functions exist (see Figure 6.8).
0120-01.jpg
Figure 6.8
Disabled menu items are visible to the
users but are shown in gray tones, indicating
that the items are currently unavailable.
Although the Visible and Enabled properties of menu items can be set at designtime using the Menu Editor, they are typically set using code at runtime in response to changes in your program's status. Just as with other objects, you can set the value of a Menu control property in code by specifying the menu item's Name property, the name of the property to be changed, and the new value.
To continue with the running example, you can enhance the simple menu system. When the program starts, no document will be open. Therefore, the File menu's Save, Send To, and Print options should not be enabled. Also, you don't want the Edit menu to be visible at all unless a document has been opened. Follow these steps to ensure that the menu system is properly set up when the program starts:
1. Make sure Form1 is selected, and then open the Menu Editor.
2. Click the Save menu item to select it.
3. Click the check box next to the Enabled property to uncheck it. This action has the effect of setting the Enabled property to False.
4. Set the Enabled property for the Send To and Print menu items to False as well.
5. Click the Edit menu item to select it.
6. Click the check box next to the Visible property to uncheck it. This action has the effect of setting the Visible property to False.
7. Close the Menu Editor.

 
< previous page page_120 next page >